package com.tanjun.userservice.web.controller.inner;

import com.tanjun.common.model.R;
import com.tanjun.userservice.apiservice.api.AdminUserApi;
import com.tanjun.userservice.apiservice.response.adminrole.admin.AdminRoleResponse;
import com.tanjun.userservice.apiservice.response.adminuser.admin.AdminUserBaseResponse;
import com.tanjun.userservice.apiservice.response.adminuser.api.AdminUserResponse;
import com.tanjun.userservice.web.biz.api.AdminUserApiBiz;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.tanjun.common.constants.UrlConstant.URL_AUTH.OPEN;
import static com.tanjun.common.constants.UrlConstant.URL_USER.INNER;

@RestController
@RequestMapping(INNER+"/adminUser")
@Slf4j
public class InnerBaseAdminUserController implements AdminUserApi {
    @Autowired
    private AdminUserApiBiz adminUserBiz;


    @Override
    @GetMapping(OPEN+"/getAdminBaseInfoByKey")
    public R<AdminUserBaseResponse> getAdminBaseInfoByKey(@RequestParam(value = "key") String key) {
        return R.OK(adminUserBiz.getAdminBaseInfoByKey(key));
    }

    /**
     * 根据用户id获取用户信息
     *
     * @param userId 用户id
     * @return 用户信息
     */
    @Override
    @GetMapping(OPEN+"/getUserInfoById")
    public R<AdminUserResponse> getUserBaseInfo(@RequestParam(value = "userId") Long userId) {
        return R.OK(adminUserBiz.getByUsrId(userId));
    }

    /**
     * 根据用户id获取角色
     *
     * @param userId 用户id
     * @return 返回角色信息
     */
    @Override
    @GetMapping(OPEN+"/getUserRoles")
    public R<List<AdminRoleResponse>> getUserRoles(@RequestParam(value = "userId")Long userId) {
        return R.OK(adminUserBiz.listRolesByUserId(userId));
    }
}
